Cap lints for upstream deps with `-vv`
authorAlex Crichton <alex@alexcrichton.com>
Mon, 13 Mar 2017 17:15:36 +0000 (10:15 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 13 Mar 2017 22:20:59 +0000 (15:20 -0700)
Previously with `-vv` Cargo didn't pass `--cap-lints` at all, but with upstream
dependencies we still want to pass at least `--cap-lints warn` to make sure that
they're all still compiling.

Closes #3823

src/cargo/ops/cargo_rustc/mod.rs
tests/registry.rs

index 14ebcc28c1f44bf930d4cbb9890801094f99d9b4..0cac00a9537779850965a54b588836d3b68c91ac 100644 (file)
@@ -249,12 +249,24 @@ fn rustc(cx: &mut Context, unit: &Unit, exec: Arc<Executor>) -> CargoResult<Work
     let mut rustc = prepare_rustc(cx, crate_types, unit)?;
 
     let name = unit.pkg.name().to_string();
+
+    // If this is an upstream dep we don't want warnings from, turn off all
+    // lints.
     if !cx.show_warnings(unit.pkg.package_id()) {
         if cx.config.rustc()?.cap_lints {
             rustc.arg("--cap-lints").arg("allow");
         } else {
             rustc.arg("-Awarnings");
         }
+
+    // If this is an upstream dep but we *do* want warnings, make sure that they
+    // don't fail compilation.
+    } else if !unit.pkg.package_id().source_id().is_path() {
+        if cx.config.rustc()?.cap_lints {
+            rustc.arg("--cap-lints").arg("warn");
+        } else {
+            rustc.arg("-Awarnings"); // not much to do on older compilers
+        }
     }
 
     let filenames = cx.target_filenames(unit)?;
index 1a60826cd2f790a89deb157f66447ec3517c56b7..d99415264d5b38582bb047f59cbe453774ed1e3f 100644 (file)
@@ -1384,3 +1384,30 @@ fn toml_lies_but_index_is_truth() {
     assert_that(p.cargo("build").arg("-v"),
                 execs().with_status(0));
 }
+
+#[test]
+fn vv_prints_warnings() {
+    Package::new("foo", "0.2.0")
+            .file("src/lib.rs", r#"
+                #![deny(warnings)]
+
+                fn foo() {} // unused function
+            "#)
+            .publish();
+
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "fo"
+            version = "0.5.0"
+            authors = []
+
+            [dependencies]
+            foo = "0.2"
+        "#)
+        .file("src/main.rs", "fn main() {}");
+    p.build();
+
+    assert_that(p.cargo("build").arg("-vv"),
+                execs().with_status(0));
+}